//ie兼容placeholder
var browserSupport = {
	placeholder: 'placeholder' in document.createElement('input')
}
$(function () {
	//模拟placeholder
	if (!browserSupport.placeholder) {
		$('input[placeholder],textarea[placeholder]').each(function () {
			var that = $(this),
				text = that.attr('placeholder'),
				oldType;
			if (that.val() === "") {
				that.val(text).addClass('placeholder');
			}
			that.focus(function () {
				//ie8下readonly依然可以上焦点的处理
				if (that.attr('readonly')) {
					that.blur();
					return;
				}
				that.removeClass('placeholder');
				if (that.val() === text) {
					that.val("");
				}
			}).blur(function () {
				if (that.val() === "") {
					that.val(text).addClass('placeholder');
					//防止异常情况：当有placeholder类，且值不为空（代码设置值时容易出现）
				} else {
					that.removeClass('placeholder');
				}
			}).closest('form').submit(function () {
				if (that.val() === text) {
					that.val('');
				}
			});
		});
	}
	//公用banner
	$(".global-banner").slide({
		titCell: ".hd ul",
		mainCell: ".bd ul",
		autoPage: true,
		autoPlay: true,
		titOnClassName: "active",
		effect: "fade",
		easing: "linear",
		delayTime: 900
	});
	$(".slideBox").slide({
		titCell: ".hd ul",
		mainCell: ".bd ul",
		autoPage: true,
		autoPlay: true,
		titOnClassName: "active",
		effect: "left",
		easing: "linear",
		delayTime: 900
	});
	$(".picScroll-left").slide({
		mainCell: ".bd ul",
		autoPage: true,
		effect: "leftLoop",
		autoPlay: true,
		vis: 5
	});
	//left
	$(".picMarquee-left").slide({
		mainCell: ".bd ul",
		autoPlay: true,
		effect: "leftMarquee",
		vis: 8,
		interTime: 50,
		trigger: "click"
	});
	$(".slideBox_list").slide({
		mainCell: ".bd ul",
		autoPage: true,
		effect: "leftLoop",
		autoPlay: false,
		vis: 5
	});
	//click
	$(".slideTxtBox").slide({
		titCell: ".hd li",
		mainCell: ".bd",
		trigger: "click"
	});
	//hover
	$(".slideBox").slide({
		titCell: ".hd li",
		mainCell: ".bd",
	});
	//hover-up
	$("body").on('mouseenter', '.hoverClick', function () {
		$(this).addClass("active");
		$(this).find(".hoverOpen").stop(false, true).slideDown();
	});
	$(".hoverClick").mouseleave(function () {
		$(this).removeClass("active");
		$(this).find(".hoverOpen").stop(false, true).slideUp();
	});
	$(".menu-nav").find("li").last("li").addClass("active").append("<i class='hot'></i>");
	$("body").on('mouseenter', '.crumbs_item .trigger', function () {
		$(this).parent(".crumbs_item").css({ "z-index": "5" });
		$(this).addClass("active");
		$(this).next(".menu_drops").stop(false, true).slideDown();
	});
	$(".crumbs_item").mouseleave(function () {
		$(this).css({ "z-index": "3" });
		$(this).find(".trigger").removeClass("active");
		$(this).find(".menu_drops").stop(false, true).slideUp();
	});
    /*
     * //checkbox
    $("label.checkbox").click(function(){
    	var _this = $(this);
    	if(_this.hasClass("active")){
			_this.parents(".item-item").removeClass("on");
		}else{
			_this.parents(".item-item").addClass("on");
		}
    	if(_this.hasClass("active")){
    		_this.removeClass("active");
    		_this.find("input").removeAttr("checked");
    		return false;
    	}else{
    		_this.addClass("active");
    		_this.find("input").attr("checked","checked");
    		return false;
    	}
    });
    //checkbox 全选
    $(".all_stars").click(function(){
    	var _this = $(this);
    	if(_this.hasClass("active")){
    		$(".checkbox_all").find("label.checkbox").addClass("active");
    		$(".checkbox_all").find("label.checkbox").parents(".item-item").addClass("on");
    	}else{
    		$(".checkbox_all").find("label.checkbox").removeClass("active");
    		$(".checkbox_all").find("label.checkbox").parents(".item-item").removeClass("on");
    	}
    });
    //checkbox 子全选
    $(".sub_stars").click(function(){
    	var _this = $(this);
    	if(_this.hasClass("active")){
    		_this.parents(".cart-list").find("label.checkbox").addClass("active");
    		_this.parents(".cart-list").find(".item-item").addClass("on");
    	}else{
    		_this.parents(".cart-list").find("label.checkbox").removeClass("active");
    		_this.parents(".cart-list").find(".item-item").removeClass("on");
    	}
    });
    */
	//checked
	$(".checkbox_button").on("click", function () {
		if ($(this).hasClass("checked")) {
			$(this).removeClass("checked");
			$(this).find("input").val("0");
		} else {
			$(this).addClass("checked");
			$(this).find("input").val("1");
		}
	});
	//table
	$(".goods_table tbody tr").hover(function () {
		$(this).addClass("hor");
	}, function () {
		$(this).removeClass("hor")
	});
	//list
	$(".member_layout_order .img-list").each(function () {
		var lang = $(this).find("li").length;
		if (lang > 4) {
			$(this).find(".more").show();
		} else {
			$(this).find(".more").hide();
		}
	});
	$('.gotop').click(function () {
		$('body,html').stop().animate({
			scrollTop: 0
		}, 800);
		return false;
	});
	$(window).on('scroll', function () {
		var $scroll = $(window).scrollTop();
		//console.log($scroll);
		if ($scroll >= 320) {
			$('.fixed-side').show();
			$('.fixed-side-rig').show();
		} else {
			$('.fixed-side').hide();
			$('.fixed-side-rig').hide();
		}
	});
	$.catetopRight = function () {
		// dom
		var lift = $("*[ectype='right']");
		var winWidth = $(window).width();
		var winHeight = $(window).height();
		var left = 0;
		if (winWidth < 1400) {
			left = ((winWidth - 1200) / 2 - lift.width()) / 2;
		} else {
			left = (winWidth - 1200) / 2 - lift.width() - 50;
		}

		var top = "50%";

		lift.css({ "right": left, "top": top });
		$(window).resize(function () {
			winWidth = $(this).width();
			left = ((winWidth - 1200) / 2 - lift.width()) / 2;
			top = "50%";

			if (winWidth < 1400) {
				left = 20;
			} else {
				left = (winWidth - 1200) / 2 - lift.width() - 50;
			}

			lift.css({ "right": left, "top": top });
		});
	}
	$.catetopRight();
	// copy
	var copyBtn = $('.copy-btn');
	copyBtn.click(function () {
		$(this).prev('input').select();
		if (document.execCommand("Copy")) {
			layer.msg('复制成功')
		} else {
			layer.msg('内容为空')
		}
	})
});
//弹窗t
function purepop(id) {
	var wi = $(id).width() + 'px';
	var index = layer.open({
		title: false,
		type: 1,
		area: 'wi',
		shadeClose: false,
		move: false,
		scrollbar: false,
		content: $(id)
	});
	$(".myclose").on("click", function () {
		layer.close(index);
	});
}